package com.zhouyx.redisactive.redisson;

import java.util.concurrent.CountDownLatch;

import org.redisson.api.RedissonClient;

/**
 * @ClassName Worker
 * @Description
 * @Author za-zhouyunxing
 * @Date 2019/4/16 17:33
 * @Version 1.0
 */
public class Worker implements  Runnable{
    private final CountDownLatch startSignal;
    private final CountDownLatch doneSignal;
    private final DistributionService service;
    private RedissonClient redissonClient;

    public Worker(CountDownLatch startSignal, CountDownLatch doneSignal, DistributionService service, RedissonClient redissonClient) {
        this.startSignal = startSignal;
        this.doneSignal = doneSignal;
        this.service = service;
        this.redissonClient = redissonClient;
    }

    @Override
    public void run() {
        try {
            startSignal.await();

            System.out.println(Thread.currentThread().getName() + " start");

            Integer count = service.aspect();
//            Integer count = service.aspect("1");


            System.out.println(Thread.currentThread().getName() + ": count = " + count);

            doneSignal.countDown();

        } catch (InterruptedException ex) {
            System.out.println(ex);
        }
    }
}
